import { fileURLToPath } from "url";
import { loadEnv, defineConfig } from "vite";
import { dirs, imports, resolver } from "./auto-import";

import uni from "@dcloudio/vite-plugin-uni";

import unocss from "unocss/vite";

import vueJsx from "@vitejs/plugin-vue-jsx";
import vueDevTools from "vite-plugin-vue-devtools";

import autoImport from "unplugin-auto-import/vite";
import components from "unplugin-vue-components/vite";

// https://vitejs.dev/config/
export default defineConfig((env) => {
  const {} = loadEnv(env.mode, process.cwd());
  return {
    plugins: [
      uni(),
      vueJsx(),
      vueDevTools(),
      unocss({
        mode: "vue-scoped",
      }),
      autoImport({
        imports: [imports, "vue", "pinia"],
        resolvers: [],
      }),
      components({
        dirs: dirs,
        resolvers: [resolver],
      }),
    ],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
        "#": fileURLToPath(new URL("./types", import.meta.url)),
      },
    },
    server: {
      proxy: {
        "^/api": {
          target: "http://27.17.28.22:8899",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
  };
});
